var table_data = {
  tid: '',arr: [],upd_leg: '', add_leg:'',
  add_url: '', upd_url: '',id_user: '',

  edit_state: function (el){
    if (table_data.tid!='') {scrl("#update_table");return};
    var elm_new, elm_current;
    table_data.tid=el.attr('id').substring(2)
    for (var i=0; i<table_data.arr.length; i++){
      elm_new=$("#update_table"+' #'+table_data.arr[i])
      elm_current=$("#tr"+table_data.tid+' #_'+table_data.arr[i])
      if (table_data.arr[i].indexOf('td_') != -1){
        elm_new.val(elm_current.text())
      } else if (table_data.arr[i].indexOf('ch_') != -1) {
        elm_new[0].checked=elm_current[0].checked
      };
    };
    table_data.show_hide();
    table_data.scrl("#update_table");
  },

  show_hide: function (){
    if (table_data.tid==''){
      $(".add").removeClass('hideme');
      $(".edit").addClass('hideme');
      $('#update_legend').text(table_data.add_leg);
    }else{
      $(".edit").removeClass('hideme');
      $(".add").addClass('hideme');
      $('#update_legend').text(table_data.upd_leg);
    }
  },

  scrl: function(elementID){
    $('html, body').animate({
      scrollTop: $(elementID).offset().top
    }, 1000);
  },

   restore_state: function (){
     var elm_new;
     for (var i=0; i<table_data.arr.length; i++){
        elm_new=$("#update_table"+' #'+table_data.arr[i])
        if (table_data.arr[i].indexOf('td_') != -1){
          elm_new.val('')
        } else if (table_data.arr[i].indexOf('ch_') != -1) {
          elm_new[0].checked=false;
        };
      };
      table_data.tid = '';
      table_data.show_hide();
    },

   send_data: function(param){
    var _url='', datstring = {}, elm;
    if (this.tid==''){
      _url = this.add_url+'?id='+this.id_user + param;
    }else{
      _url = this.upd_url+'?id='+this.id_user+'&el='+this.tid+param;
    };
    $("#update_form").attr('action', encodeURI(_url));
    $("#update_form").submit()
   }
};




